# -*- coding:UTF-8 -*-
import requests
from bs4 import BeautifulSoup
from pprint import pprint

if __name__ == '__main__':
    headers = {
        'User-Agent':
            'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.182 Safari/537.36'
    }
    url = 'https://read.qidian.com/chapter/SaJ9L6aSg4E1/RVkDZcwLjh4ex0RJOkJclQ2'
    req = requests.get(url=url, headers=headers)
    html = req.text
    bf = BeautifulSoup(html, features="html.parser")
    # chapter-29577944 > div > div.read-content.j_readContent > p > span.content-wrap
    texts = bf.find_all('div', class_='read-content j_readContent')
    content = texts[0].text.replace('\u3000' * 2, '\n')
    try:
        with open('遮天.txt', 'w+', encoding='utf-8') as file:
            file.write(content)
    except Exception as e:
        pprint(e)
    # pprint(content)
